package com.example.couponprovider.dubbo;

import com.example.couponprovider.domain.Coupon;
import com.example.couponprovider.service.ICouponService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.example.api.CouponApi;
import org.example.dto.CouponDto;
import org.example.response.R;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 用于验证A->B->C时全局事务处理
 * @author Kong
 * @date 2021-9-13 22:09
 */
@Slf4j
@DubboService
public class CouponDubboService implements CouponApi {
    @Autowired
    private ICouponService couponService;
    @Override
    public R issueCoupon(CouponDto dto) {
        log.info("全局事务XID："+ RootContext.getXID());
        Coupon coupon = new Coupon();
        coupon.setAccount(1);
        coupon.setCouponId(1);
        coupon.setUserId(1);
        couponService.save(coupon);
        return R.Builder.getInstance().buildOk().build();
    }
}
